#include <stdio.h>
#include <string.h>
#define N 1000005
int ans[N];
int queue[N];
int head, tail;
int n, k;
bool init()
{
    if (scanf("%d%d", &n, &k)==EOF) return false;
    return true;
}    
void deal()
{
    int item, toitem;
    int step = 0;
    memset(ans, 0, sizeof(ans));
    head = 0;
    tail = 1;
    queue[0] = n;
    ans[n] = 1;
    while (ans[k]==0)
    {
        item = queue[head++];
        step = ans[item];
        if (item == k) break;
        if (head == N) 
               head = 0;
        toitem = item - 1;
        if (toitem >=0 && ans[toitem]==0){
            queue[tail++] = toitem;
            ans[toitem]=step+1;
        }    
        toitem = item + 1;
        if (toitem < N && ans[toitem]==0){
            queue[tail++] = toitem;
            ans[toitem]=step+1;
        }   
        toitem = item *2;
        if (toitem < N && ans[toitem]==0) {
            queue[tail++] = toitem;        
            ans[toitem]=step+1;
        }   
    }
    printf("%d\n", ans[k]-1);    
}    
int main()
{
    while (init())
    {
        deal();
    }    
    return 0;
}    

